package com.hean.util;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

import com.hean.entity.Resource;

public class SAXParseService {
	public static Resource parseXml(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException{
		SAXParserFactory factory=SAXParserFactory.newInstance();
		SAXParser parser=factory.newSAXParser();
		//设置解析器相关特性，http://xml.org/sax/features/namespaces=true，表示开启命名空间
//		parser.setProperty("http://xml.org/sax/features/namespaces", true);
		XMLContentHandler handler=new XMLContentHandler();
		parser.parse(inputStream, handler);
		inputStream.close();
		return handler.getResource();
	}
}
